<template>
  <div class="index-container">
    <Header title="每日健康申报信息"></Header>
    <div class="warpper">
      <van-form @submit="onSubmit">
        <van-field v-model="selfUserInfo.id" name="id" label="主键" placeholder="主键" readonly v-show="false" />
        <van-field
          v-model="selfUserInfo.user_id"
          name="user_id"
          label="用户主键"
          placeholder="用户主键"
          readonly
          v-show="false"
        />
        <van-field v-model="selfUserInfo.fakexm" name="fakexm" label="姓名" placeholder="姓名" readonly disabled />
        <van-field name="xb" label="性别"  readonly disabled>
          <template #input>
            <van-radio-group v-model="selfUserInfo.xb" direction="horizontal" disabled>
              <van-radio name="male">男</van-radio>
              <van-radio name="female">女</van-radio>
            </van-radio-group>
          </template>
        </van-field>
        <van-field
          v-model="selfUserInfo.fakeidcard"
          name="fakeidcard"
          label="证件号码"
          placeholder="证件号码"
          readonly
          disabled
        />
        <van-field
          v-model="selfUserInfo.faketel"
          name="faketel"
          label="手机号码"
          placeholder="手机号码"
          readonly
          disabled
        />
        <van-field v-model="selfUserInfo.sbrq" name="sbrq" label="申报日期" placeholder="申报日期" readonly disabled />
        <p class="health">个人健康情况</p>
        <van-field name="jkzk" :rules="[{ required: true, message: '请选择个人健康情况' }]">
          <template #input>
            <van-checkbox-group v-model="selfUserInfo.jkzk" @change="checkChange">
              <van-checkbox :name="1" shape>14天内曾居住或前往疫情高发地</van-checkbox>
              <van-checkbox :name="2" shape>两周内有与确诊患者接触</van-checkbox>
              <van-checkbox :name="3" shape>最近一个月是否有国外/境外旅居史</van-checkbox>
              <van-checkbox :name="4" shape>没有出现症状</van-checkbox>
              <van-checkbox :name="5" :disabled="checkDisabled" shape
                >感冒样症状：乏力、精神差、咳嗽、发烧、肌肉疼、头疼</van-checkbox
              >
              <van-checkbox :name="6" :disabled="checkDisabled" shape>喘憋、呼吸急促</van-checkbox>
              <van-checkbox :name="7" :disabled="checkDisabled" shape>恶心呕吐、腹泻</van-checkbox>
              <van-checkbox :name="8" :disabled="checkDisabled" shape>心慌、胸闷</van-checkbox>
              <van-checkbox :name="9" :disabled="checkDisabled" shape
                >结膜炎（红眼病样表现：眼睛涩、红、分泌物）</van-checkbox
              >
            </van-checkbox-group>
          </template>
        </van-field>
        <van-field v-model="selfUserInfo.bz" name="bz" label="备注" placeholder="备注" />

        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit">提交</van-button>
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import { saveHealthInfo } from 'api/userInfo'
import { getSelfInfo } from '@/utils/tokenUtil'
import { parseTime } from '@/utils/'
export default {
  name: 'IllnessReport',

  data() {
    return {
      selfUserInfo: {
        fakexm: '',
        fakeidcard: '',
        faketel: '',
        xb: '',
        id: '',
        jkzk: [],
        user_id: '',
        sbrq: ''
      },
      checkDisabled: false
    }
  },
  created() {
    this.loadUserInfoFromCenter()
  },
  methods: {
    onSubmit(data) {
      debugger
      this.$dialog
        .confirm({
          message: '点击确认视同承诺信息真实有效，如有虚报瞒报信息需承担相应发了责任'
        })
        .then(() => {
          delete data.fakexm
          delete data.faketel
          delete data.fakeidcard
          delete data.xb
          console.log('个人每日健康申报保存操作')
          data.aae036 = '2021-02-01'
          data.jkzk = JSON.stringify(data.jkzk)
          saveHealthInfo(data)
            .then(res => {
              debugger
              if (res.code == 200) {
                this.$dialog.alert({
                  message: '保存成功'
                })
              }
            })
            .catch(err => {
              console.log('个人每日健康申报保存失败：' + err)
              this.$dialog.alert({
                title: '错误信息',
                message: '保存失败'
              })
            })
        })
        .catch(() => {
          // on cancel
        })
    },
    checkChange(name) {
      if (name.indexOf(4) != -1) {
        this.checkDisabled = true
        if (
          name.indexOf(5) != -1 ||
          name.indexOf(6) != -1 ||
          name.indexOf(7) != -1 ||
          name.indexOf(8) != -1 ||
          name.indexOf(9) != -1
        ) {
          name = name.filter(item => item <= 4)
          this.selfUserInfo.jkzk = name
        }
      } else {
        this.checkDisabled = false
      }
    },
    loadUserInfoFromCenter() {
      let selfInfo = getSelfInfo()
      this.selfUserInfo.fakexm = selfInfo.fakexm
      this.selfUserInfo.xb = selfInfo.xb
      this.selfUserInfo.fakeidcard = selfInfo.fakeidcard
      this.selfUserInfo.faketel = selfInfo.faketel
      this.selfUserInfo.user_id = selfInfo.id
      let date = new Date().toString()
      this.selfUserInfo.sbrq = parseTime(date, '{y}-{m}-{d}')
    }
  }
}
</script>

<style lang="scss" scoped>
.health {
  font-size: 0.6rem;
  font-weight: bold;
  background: white;
  margin: 0;
  padding: 20px 10px 10px;
}
/deep/ .van-checkbox {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 10px;
  }
}
</style>
